package com.byd.dms.sf_json.service;


import com.byd.dms.sf_json.entity.People;
import com.byd.dms.sf_json.entity.Role;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

/**
 * @Description:模拟数据信息
 * 一个人可以有多个角色，例如：在家中是儿子，在学校是学生，在公司是程序员，一个人还可以办好多业务
 * 每个业务好多个人都可以办，则标记（mark）就是记录这唯一标识的(如id)业务和称职
 * @date 2018年7月22日,下午2:26:52
 */
public class SimulationData {
    
    // 保存用户账户的唯一标记
    private static List<String> markLists = new ArrayList<String>();
    /**
     *
     * @Description: user模拟数据
     * @param @param userCount user对象个数
     * @param @return
     * @return List<User>
     * @throws
     */
    public static List<Role> dataRole(int roleCount) {
        long start = System.currentTimeMillis();
        System.out.println("/**********************《start添加User信息内容》********************/");
        List<Role> roleList = new ArrayList<Role>();
        for (int i = 1; i <= roleCount; i++) {
            Role role = new Role();
            String mark = RandomDemo.getRandom(10, RandomDemo.TYPE.NUMBER);
            markLists.add(mark);
            role.setMark(mark);
            role.setName(RandomDemo.getRandom(5, RandomDemo.TYPE.LETTER_CAPITAL));
            Integer age = Integer.parseInt(RandomDemo.getRandom(2, RandomDemo.TYPE.NUMBER));
            role.setAge(age);
            role.setSex(RandomDemo.getRandom(2, RandomDemo.TYPE.LETTER_CAPITAL));
            roleList.add(role);
        }
        for (int i = 0; i < roleList.size(); i++) {
            System.out.println("第" + (i + 1) + "组User数据");
            System.out.print("      " + "name:" + roleList.get(i).getName() + ",age:" + roleList.get(i).getAge()
                    + ",sex:" + roleList.get(i).getSex() + ",mark:" + roleList.get(i).getMark());
            System.out.println();
        }
        long end = System.currentTimeMillis();
        System.out.println("Role数据产生时间："+(end-start));
        System.out.println("/**********************《end添加User信息内容》********************/");
        return roleList;
    }
    
    /**
     *
     * @Description: people模拟数据信息
     * @param @param peopleCount people对象个数
     * @param @param markCount 一个prople对应的标记个数
     * @param @return
     * @return List<People>
     * @throws
     */
    public static List<People> dataPeople(int peopleCount, int markCount) {
        
        System.out.println("/**********************《start添加People信息内容》********************/");
        long start = System.currentTimeMillis();
        List<People> peopleList = new ArrayList<People>();
        for (int i = 1; i <= peopleCount; i++) {
            People people = new People();
            people.setMessage(RandomDemo.getRandom(5, RandomDemo.TYPE.LETTER_CAPITAL));
            // 去除重复的数字标记
            Set<String> markSet = new HashSet<String>();
            // 每个Prople类下有markCount个标记mark
            Random random = new Random();
            for (int j = 1; j <= markCount; j++) {
                int n = random.nextInt(markLists.size());
                markSet.add(markLists.get(n));
            }
            people.setMarkSet(markSet);
            peopleList.add(people);
        }
        for (int i = 0; i < peopleList.size(); i++) {
            System.out.println("第" + (i + 1) + "组People数据");
            System.out.print("      mark标记列表" + peopleList.get(i).getMarkSet().toString() + ",message:"+ peopleList.get(i).getMessage());
            System.out.println();
        }
        long end = System.currentTimeMillis();
        System.out.println("People数据产生时间："+(end-start));
        System.out.println("/**********************《end添加People信息内容》********************/");
        return peopleList;
    }
}